<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset=utf-8>
  <meta http-equiv=X-UA-Compatible content="IE=edge">
  <meta name=viewport
    content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=0,shrink-to-fit=no">
  <meta name=format-detection content="telephone=no">
  <meta name=renderer content=webkit>
  <meta name=description content="">
  <meta name=keywords content="">
  <meta http-equiv=Cache-Control content="no-cache, no-store, must-revalidate">
  <meta http-equiv=Pragma content=no-cache>
  <meta http-equiv=Expires content=0>
  <meta name=renderer content=webkit>
  <meta name=mobile-web-app-capable content=yes>
  <meta name=apple-mobile-web-app-status-bar-style content=black>
  <meta name=apple-mobile-web-app-title content=创客匠人>
  <meta http-equiv=x-dns-prefetch-control content=on>
  <script src="https://assets.ckjr001.com/axios-v0.15.3.min.js"></script>
  <script src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
  <style>
    .launch-top {
      padding-top: 45px;
      display: flex;
      display: -webkit-flex;
      flex-direction: row;
      -webkit-flex-direction: row;
      align-items: center;
      -webkit-align-items: center;
      justify-content: center;
      -webkit-justify-content: center;
    }

    .icon-img {
      height: 30px;
      width: 30px;
    }

    .top-text {
      font-size: 16px;
      font-weight: bold;
      color: #333333;
      margin-left: 8px;
    }

    .img-center {
      display: block;
      width: 68%;
      margin: 60px auto 0;
    }

    .launch-btn-wrap {
      font-size: 14px;
      color: #fff;
      text-align: center;
      width: 70%;
      height: 36px;
      line-height: 36px;
      margin: 50px auto 0;
      border-radius: 18px;
      background: #67C4AB;
      position: relative;
    }

    .ckjr-text {
      font-size: 14px;
      font-weight: bold;
      color: #333333;
      text-align: center;
      margin-top: 60px;
    }

    .company-info {
      font-size: 12px;
      color: #999999;
      text-align: center;
      margin-top: 4px;
    }
    .open-tag-wrap {
      position: absolute;
      z-index: 10;
      left: 0;
      right: 0;
      top: 0;
      bottom: 0;
      background-color: transparent;
    }
    .launch-btn {
      width: 100%;
      height: 100%;
      display: block;
      overflow: hidden;
    }
    .masker {
      position: fixed;
      top: 0;
      left: 0;
      z-index: 1002;
      width: 100%;
      height: 100%;
      background-color: rgba(0, 0, 0, 0.4);
    }

    .c-mh24 {
      margin: 0 12px;
    }

    .c-p {
      position: relative;
    }

    .content {
      width: 90%;
      position: fixed;
      top: 20px;
      z-index: 1003;
      max-width: 640px;
      left: 50%;
      transform: translate(-50%);
      padding: 10px 12px;
      border-radius: 10px;
      background-color: #fff;
    }

    .content>div>img {
      width: 1.2rem;
      height: 2.2rem;
      position: absolute;
      top: 0.4rem;
      right: 0.3rem;
      z-index: 1004;
    }

    .imgbox {
      width: 1.6rem;
      height: 0.8rem;
      margin-left: 0.2rem;
      margin-right: 0.4rem;
    }

    .c-fs28 {
      font-size: 14px;
    }

    .c-fs22 {
      font-size: 12px;
    }

    .c-mt10 {
      margin-top: 5px;
    }

    .c-flex-row {
      display: flex;
      display: -webkit-flex;
      flex-direction: row;
      -webkit-flex-direction: row;
    }
  </style>
</head>

<body>
  <div id="downNotice" style="display: none;">
    <div class="masker"></div>
    <div class="c-mh24 c-p">
      <div class="content">
        <div class="">
          <img src="">
        </div>
        <p class="c-fs28">温馨提示</p>
        <p class="c-fs22 c-mt10 c-flex-row">点击右上角的
          <img src="" class="imgbox">选择在浏览器打开即可下载或打开App
        </p>
      </div>
    </div>
  </div>
  <div class="launch-top ">
    <img class="icon-img"
      src=""
      alt="">
    <div class="top-text">打开创客匠人学员版APP开始学习吧</div>
  </div>
  <img class="img-center"
    src=""
    alt="">
  <div id="wx-browser-btn" class="launch-btn-wrap">打开APP
    <div class="open-tag-wrap">
      <wx-open-launch-app
        class="launch-btn"
        id="launch-btn"
        appid="wxe6beaa1de8fa55e8"
      >
        <script type="text/wxtag-template">
          <!-- 这里是为了撑开元素，让其可以被点击，不添加template会报错，添加了template不添加内容也会报错 -->
          <div style="padding: 10000px">
          </div>
        </script>
      </wx-open-launch-app>
    </div>
  </div>
  <div onclick="goApp()" id="other-browser-btn" class="launch-btn-wrap">打开APP
    <div class="open-tag-wrap">
    </div>
  </div>
  <div class="ckjr-text">创客匠人学员版APP</div>
  <div class="company-info">厦门创匠信息科技股份有限公司</div>
  <script>
    var paramStrArr = '';
    function goApp() {
      var u = window.navigator.userAgent;
      var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1; //android终端或者uc浏览器
      var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
      if(/MicroMessenger/gi.test(u)) {
        // 引导用户在浏览器中打开
          alert('请在浏览器中打开');
          return;
      }
      if (isAndroid) {
        android();
      }
      if (isiOS) {
        ios();
      }
    };
    function android() {
      var _clickTime = new Date().getTime();
      // window.location.href = 'alipays://platformapi/startapp?appId=20000123'; /***打开app的协议，有安卓同事提供***/
      window.location.href = 'ckjrflutter://lyyueapp/detail?' + paramStrArr;
      //启动间隔20ms运行的定时器，并检测累计消耗时间是否超过3000ms，超过则结束
      var _count = 0,
        intHandle;
      intHandle = setInterval(function () {
        _count++;
        var elsTime = new Date().getTime() - _clickTime;
        if (_count >= 250 || elsTime > 5000) {
          console.log(_count)
          console.log(elsTime)
          clearInterval(intHandle);
          //检查app是否打开
          if (document.hidden || document.webkitHidden) {
            // 打开了
            window.close();
          } else {
            // 没打开
            // alert('没打开')
            window.location.href = "https://kpreport.ckjr001.com/studyAppDownload.html";//下载链接
          }
        }
      }, 20);

    }
    function ios() {
      // var _clickTime = new Date().getTime();
      // window.location.href = 'alipays://platformapi/startapp?appId=20000123'; /***打开app的协议，有安卓同事提供***/
      window.location.href = 'ckjrflutter://lyyueapp/detail?' + paramStrArr;
      setTimeout(() => {
        location.href = "https://kpreport.ckjr001.com/studyAppDownload.html";//下载链接
      }, 250);
      setTimeout(() => {
        location.reload();
      }, 1000);
      //启动间隔20ms运行的定时器，并检测累计消耗时间是否超过3000ms，超过则结束
      // var _count = 0,
      //   intHandle;
      // intHandle = setInterval(function () {
      //   _count++;
      //   var elsTime = new Date().getTime() - _clickTime;
      //   if (_count >= 250 || elsTime > 5000) {
      //     console.log(_count)
      //     console.log(elsTime)
      //     clearInterval(intHandle);
      //     //检查app是否打开
      //     if (document.hidden || document.webkitHidden) {
      //       // 打开了
      //       window.close();
      //     } else {
      //       // 没打开
      //       // alert('没打开')
      //       window.location.href = "https://kpreport.ckjr001.com/studyAppDownload.html";//下载链接
      //     }
      //   }
      // }, 20);
    }
    // function ios() {
    //   var _clickTime = +(new Date());
    //   var ifr = document.createElement("iframe");
    //   ifr.src = 'ckjrflutter://lyyueapp/detail?' + paramStrArr; /***打开app的协议，有ios同事提供***/
    //   ifr.style.display = "none";
    //   document.body.appendChild(ifr);
    //   //启动间隔20ms运行的定时器，并检测累计消耗时间是否超过3000ms，超过则结束
    //   var _count = 0,
    //     intHandle;
    //   intHandle = setInterval(function () {
    //     _count++;
    //     var elsTime = +(new Date()) - _clickTime;
    //     console.log(_count, elsTime, +(new Date()), _clickTime)
    //     if (_count >= 250 || elsTime > 5000) {
    //       clearInterval(intHandle);
    //       document.body.removeChild(ifr);
    //       //检查app是否打开
    //       if (document.hidden || document.webkitHidden) {
    //         // 打开了
    //         window.close();
    //       } else {
    //         // 没打开
    //         // alert('没打开')
    //         window.location.href = "https://kpreport.ckjr001.com/studyAppDownload.html";//下载链接
    //       }
    //     }
    //   }, 20);
    // }
    function showToast(type, time = 2000) {
      document.querySelector('#myToast').classList.add("toast-show");
      var classId = '.toast-' + type;
      document.querySelector(classId).classList.add("toast-show");
      setTimeout(() => {
        document.querySelector('#myToast').classList.remove("toast-show");
        document.querySelector(classId).classList.remove("toast-show");
        window.history.go(-2)
      }, time);
    };
    //获取微信支付和sdk初始化参数
    function getWechatConfig(data) {
      var apiUrl = 'https://kpapiop.ckjr001.com';
      if (window.location.host.indexOf('kptest.ckjr001') > -1) {
        apiUrl = 'https://kpapi-cs.ckjr001.com';
      } else if (window.location.host.indexOf('formal.ckjr001') > -1) {
        apiUrl = 'https://formalapi.ckjr001.com'
      }
      if (sessionStorage.getItem('promotedAccountId')) {
        data.promotedAccountId = sessionStorage.getItem('promotedAccountId')
      }
      axios.post(apiUrl + '/api/mp/jsConfig', data)
        .then(function (res) {
          if (res.data.statusCode == 200) {
            initWxConfig(res.data.data);
          }
        })
        .catch(function (error) {
          console.log(error);
        });
    };
    //初始化sdk
    function initWxConfig(configData) {
      wx.config(configData);
      console.log('configData', configData);
      wx.ready(function () {
        console.log('wxready');
        wx.hideMenuItems({
          menuList: [
            'menuItem:share:appMessage',
            'menuItem:share:timeline',
            'menuItem:share:qq',
            'menuItem:share:weiboApp',
            'menuItem:favorite',
            'menuItem:share:facebook',
            'menuItem:share:QZone',
            'menuItem:editTag',
            'menuItem:delete',
            'menuItem:copyUrl',
            'menuItem:originPage',
            'menuItem:readMode',
            'menuItem:openWithQQBrowser',
            'menuItem:openWithSafari',
            'menuItem:share:email',
            'menuItem:share:brand',
          ]
        });
        var btn = document.getElementById('launch-btn');
        btn.setAttribute('extinfo', paramStrArr)
        btn.addEventListener('launch', function (e) {
          console.log('success');
        });
        btn.addEventListener('error', function (e) {
          console.log('fail', e.detail);
          document.getElementById('downNotice').style.display = 'block';
          // window.location.replace('https://kpreport.ckjr001.com/studyAppDownload.html');
        });
      });
    }

    window.onload = function () {
      document.getElementById('downNotice').style.display = 'none';
      //获取url上带的参数
      paramStrArr = window.location.href.split('?').length > 1 ? window.location.href.split('?')[1] : [];
      console.log('vvvv', paramStrArr)

      if (
        window.navigator.userAgent.toLowerCase().match(/MicroMessenger/i) !=
        "micromessenger"
      ) {
        document.getElementById('wx-browser-btn').style.display = 'none';
        document.getElementById('other-browser-btn').style.display = 'block';
      } else {
        document.getElementById('wx-browser-btn').style.display = 'block';
        document.getElementById('other-browser-btn').style.display = 'none';
      }
        var data = {
          "url": window.location.href,
          "jsApiList": ["onMenuShareTimeline"],
          "openTagList": ['wx-open-launch-app'],
          "companyId": window.location.host.indexOf('.wx.') > -1 ? '26e3' : "lj7l"
        }
        getWechatConfig(data);
        return;
    };
  </script>
</body>

</html>